package com.dyh.quickdemo.GoodsRules;

import java.util.List;
import java.util.function.Function;

/*
@Author=Joey Wheeler
@Date=2021/3/6 10:43
*/
public class Rule$1<T,V1> implements Rule<T>{
    private Function<T,V1> mapper;
    private List<CheckerAndTip<Checker$1<V1>>> checkerAndTips;

    public Rule$1(Function<T, V1> mapper, List<CheckerAndTip<Checker$1<V1>>> checkerAndTips) {
        this.mapper = mapper;
        this.checkerAndTips = checkerAndTips;
    }

    public CheckResult check(T obj){
        V1 v1 = mapper.apply(obj);
        for (CheckerAndTip<Checker$1<V1>> checkerAndTip : checkerAndTips) {
            if (checkerAndTip.getChecker().test(v1))
                continue;
            return new CheckResult(false,checkerAndTip.getTip());
        }
        return new CheckResult(true,"");
    }




}
